package com.geek.java.ch04.map;

import java.util.Scanner;
import java.util.TreeMap;

public class TreeMapTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串");
        String str = sc.nextLine();


        TreeMap<Character, Integer> treeMap = new TreeMap<>();

        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            int count = 0;


            for (int j = 0; j < str.length(); j++) {
                if (ch == str.charAt(j)) {
                    count++;
                }
            }
            treeMap.put(ch, count);
        }


        treeMap.keySet().forEach(key -> {
            System.out.println("key = " + key + ", value = " + treeMap.get(key));
        });

    }
}

